﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using KMS.Core.domain.model.alert;
using KMS.Web.Views.News;
using KMS.Web.Tests.Factory;
using KMS.Core.domain.model.project;

namespace KMS.Web.Tests.views
{
    /// <summary>
    /// Summary description for ProjectEventViewModelTests
    /// </summary>
    [TestClass]
    public class SystemAlertViewModelTests
    {
        private SystemAlertFactory _factory;

        public SystemAlertViewModelTests()
        {
            _factory = new SystemAlertFactory();
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void SystemAlertViewModelCanBeConstructed()
        {
            var dateTime = DateTime.Now.AddDays(-10);
            var project = new Project("my project");
            var systemAlert = _factory.Create("some text", dateTime, project);
            var systemAlertVM = new SystemAlertViewModel(systemAlert, 15);

            Assert.AreEqual("some text", systemAlertVM.DisplayedText);
            Assert.AreEqual("some text", systemAlertVM.FullText);
            Assert.AreEqual(dateTime.ToString("dd MMM HH:mm"), systemAlertVM.DateTime);
            Assert.AreEqual("my project", systemAlertVM.ProjectName);
        }

        [TestMethod]
        public void IfDisplayCharIsLessThanTextLengthViewModelCutsLongText()
        {
            var systemAlert = _factory.Create("this is a long text");
            var systemAlertVM = new SystemAlertViewModel(systemAlert, 10);
            Assert.AreEqual("this is a ...", systemAlertVM.DisplayedText, "long text is not cut");
            Assert.IsTrue(systemAlertVM.DisplayReadMore, "DisplayReadMore should be true");
        }

        [TestMethod]
        public void IfDisplayCharIsEqualToTextLengthViewModelDoesntCutText()
        {
            var systemAlert = _factory.Create("this is a long text");
            var systemAlertVM = new SystemAlertViewModel(systemAlert, 19);
            Assert.AreEqual("this is a long text", systemAlertVM.DisplayedText, "Short text is cut");
            Assert.IsFalse(systemAlertVM.DisplayReadMore, "DisplayReadMore should be false");
        }

        [TestMethod]
        public void IfDisplayCharIsGreaterThanTextLengthViewModelDoesntCutText()
        {
            var systemAlert = _factory.Create("this is a long text");
            var systemAlertVM = new SystemAlertViewModel(systemAlert, 25);
            Assert.AreEqual("this is a long text", systemAlertVM.DisplayedText, "Short text is cut");
            Assert.IsFalse(systemAlertVM.DisplayReadMore, "DisplayReadMore should be false");
        }
    }
}
